package com.penjin.android.activity.secretary;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.widget.Toast;

import com.easemob.util.NetUtils;
import com.loopj.android.http.RequestParams;
import com.loopj.android.http.TextHttpResponseHandler;
import com.penjin.android.constants.HttpConstants;
import com.penjin.android.http.HttpService;

import org.apache.http.Header;
import org.json.JSONArray;
import org.json.JSONObject;

/**
 * Created by lxl on 2016/4/1.
 */
public class testPushListActivity extends Activity{

    private Context context = this ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Intent intent = getIntent() ;

        String id = intent.getStringExtra("id") ;

        init(id);

    }


    public void init( String id ){


            HttpService httpService = HttpService.getInstance(this);
            //判断网络是否正常
            if (NetUtils.hasNetwork(this)) {
                try {

                    RequestParams requestParams = new RequestParams();
                    requestParams.put("companyId", "0000000008");
                    requestParams.put("userName", "15608222863");
                    requestParams.put("id", id);
                    httpService.postRequest(this, HttpConstants.HOST + HttpConstants.CompanyPushDetail, requestParams, new TextHttpResponseHandler() {
                        @Override
                        public void onFailure(int i, Header[] headers, String s, Throwable throwable) {
                            if (s == null) {
                                Toast.makeText(context, "服务器内部错误", Toast.LENGTH_SHORT).show();
                            } else {
                                System.out.println(s);
                                Toast.makeText(context, "资源路径出错", Toast.LENGTH_SHORT).show();
                            }
                        }

                        @Override
                        public void onSuccess(int i, Header[] headers, String s) {
                            try {

                                Log.d("JPush",s) ;

                                JSONObject jo = new JSONObject(s);
                                if (jo.getBoolean("result")) {

                                    String title = jo.getString("title") ;
                                    String content = jo.getString("content") ;
                                    String pushTime = jo.getString("pushTime") ;
                                    String pushPerson = jo.getString("pushPerson") ;

                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    });
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                Toast.makeText(this, "网络不可用...", Toast.LENGTH_SHORT).show();
            }



    }

}
